package com.kitty.game.gm.handler;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.service.FightService;
import com.kitty.game.gm.GmService;
import com.kitty.game.role.model.Role;
import com.kitty.mina.message.MessagePusher;

public class GmQuitFight implements GMFather {

    @Override
    public boolean handle(Role aaaaa, String content) {
        GmService gmService = SpringUtils.getBean(GmService.class);
        String name = gmService.replaceName(content);
        Role role = SpringUtils.getRoleService().getOnlinePlayer(name);
        if (role == null){
            MessagePusher.pushMessage(aaaaa,new RespNotifyMiscEx("玩家不在线！！"));
            return true;
        }
        FightService fightService = SpringUtils.getBean(FightService.class);
        Fight fight = fightService.getFightByRoleId(role.getRoleId());
        if (fight == null) {
            MessagePusher.pushMessage(aaaaa,new RespNotifyMiscEx("玩家不在战斗中！！"));
            return true;
        }
        fightService.quitFight(fight);
        MessagePusher.pushMessage(aaaaa,new RespNotifyMiscEx("玩家#R"+name+"#n退出战斗成功！！"));
        return true;
    }
}
